using UnityEngine;

public class ZoneMusic : MonoBehaviour
{
	public ZoneId idZone = ZoneId.city;

	private void OnTriggerEnter(Collider other)
	{
		if (other.tag == "Player")
		{
			Mortal componentInParent = other.GetComponentInParent<Mortal>();
			if (componentInParent != null && IsMe(componentInParent))
			{
				BackgroundSoundManager.instance.EnterZone(this);
			}
		}
	}

	private void OnTriggerExit(Collider other)
	{
		if (other.tag == "Player")
		{
			Mortal componentInParent = other.GetComponentInParent<Mortal>();
			if (componentInParent != null && IsMe(componentInParent))
			{
				BackgroundSoundManager.instance.ExitZone(this);
			}
		}
	}

	private bool IsMe(Mortal curB)
	{
		return curB == GameController.instance.playerScript || curB == GameController.instance.carScript;
	}
}
